<?php 
//模型：广告管理
//model/class.ads.php
//By QINIAO

class qiAds
{
	var $db;
	
	function qiAds($dbhandle)
	{
		$this->db = $dbhandle;
	}
	
	//添加广告
	function addAds($adName,$adContent)
	{
	$sql = "insert into ".DB_PREFIX."ads (name,content) values ('$adName','$adContent')";
	$this->db->query($sql);
	}
	
	//广告列表（所有广告）
	function getAds()
	{
	$res = $this->db->query("select * from ".DB_PREFIX."ads order by id desc");
	$ads = array();
	while($row = $this->db->fetch_array($res))
	{
	$row['name'] = htmlspecialchars($row['name']);
	$row['content'] = htmlspecialchars($row['content']);
	$ads[] = $row; 
	}
	return $ads;
	}
	
	//获取一条广告
	function getOneAds($aid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."ads where id=$aid");
	$row = $this->db->fetch_array($res);
	$adDate = array();
	if($row)
	{
	$adDate = array(
	'name' => $row['name'],
	'content' => $row['content']
	);
	}
	return $adDate;
	}
	
	//获取广告内容
	function getAD($aid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."ads where id=$aid");
	$row = $this->db->fetch_array($res);
	return $row['content'];
	}
	
	//更新广告
	function updateAds($adDate,$aid)
	{
	$Item = array();
	foreach($adDate as $key=>$date)
	{
	$Item[] = "$key='$date'";
	}
	$upStr = implode(',',$Item);
	$this->db->query("update ".DB_PREFIX."ads set $upStr where id=$aid");
	}
	
	//删除广告
	function deleteAds($aid)
	{
	$this->db->query("delete from ".DB_PREFIX."ads where id=$aid");
	}
	
	}

?>